<template>
  <div class="register">
    <h2>用户注册</h2>
    <form @submit.prevent="register">
      <div>
        <label>用户名：</label>
        <input v-model="username" required />
      </div>
      <div>
        <label>密码：</label>
        <input type="password" v-model="password" required />
      </div>
      <button type="submit">注册</button>
      <p>已有账号？<router-link to="/login">去登录</router-link></p>
    </form>
  </div>
</template>

<script setup>
// 注册页，用户输入用户名和密码进行注册
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { useUserStore } from '../stores/user'

const username = ref('')
const password = ref('')
const router = useRouter()
const userStore = useUserStore()

function register() {
  // 简单模拟注册逻辑
  if (username.value && password.value) {
    userStore.register(username.value)
    alert('注册成功！')
    router.push('/login')
  } else {
    alert('请输入用户名和密码')
  }
}
</script>

<style scoped>
.register {
  padding: 20px;
}
</style> 